import { _decorator, Component, Node, Vec3 } from 'cc';
import { Singleton } from './comm/Singleton';
const { ccclass, property } = _decorator;

@ccclass('GameData')
export class GameData extends Singleton<GameData> {

    levelMap = new Map<number,LevelData>();

    public createLevel(level: number){
        switch(level){
            case 1:
                let level1 = new LevelData();
                level1.level = 1;
                level1.row = 10;
                level1.col = 7;
                level1.mineNum = 10;
                level1.safeDistance = 300;
                level1.scale = Vec3.ONE;
                return level1;
                break;
            case 2:
                let level2 = new LevelData();
                level2.level = 2;
                level2.row = 22;
                level2.col = 12;
                level2.mineNum = 40;
                level2.safeDistance = 500;
                level2.scale = new Vec3(2,2,2);
                return level2;
                break;
            case 3:
                let level3 = new LevelData();
                level3.level = 3;
                level3.row = 32;
                level3.col = 18;
                level3.mineNum = 200;
                level3.safeDistance = 1000;
                level3.scale = new Vec3(3,3,3);
                return level3;
                break;
        }
    }

    public hasLevel(level: number){
        return this.levelMap.has(level);
    }


    public getLevel(level: number){
        return this.levelMap.get(level);
    }

    public saveLevel(level: number ,levelData: LevelData){
        this.levelMap.set(level,levelData);
        console.log('Save Level :' + level + 'level Data' + levelData);
    }

}

@ccclass('CellData')
export class CellData{
    index: number;
    IsFilp: boolean;
    IsHide: boolean;
    IsMine: boolean;
    MineNum: number;

    constructor(
        index: number,
        IsFilp: boolean = false,
        IsHide: boolean = false,
        IsMine: boolean = false,
        MineNum: number = 0
    ) {
        this.index = index;
        this.IsFilp = IsFilp;
        this.IsHide = IsHide;
        this.IsMine = IsMine;
        this.MineNum = MineNum;
    }
}

@ccclass('LevelData')
export class LevelData{
    level: number;
    row: number;
    col: number;
    mineNum: number;
    recardStep: number[] = [];
    stepLeftOrRight: number[] = [];
    mineList: number[] = [];
    cellList:CellData[] = [];


    safeDistance: number;
    position: Vec3;
    orthoHeight: number;
    scale: Vec3;
}


